#include "AE.h"

IParticleSystemSceneNode* makeSimpleParticleSystem(const c8* particleTextFilePath, dimension2d<f32> particleSize, 
bool hasLight,video::SColorf lightColor, float lightRange, bool hasBillBoard, const c8* billBoardFilePathImg, 
core::aabbox3d<f32> boxEmmitterSize, core::vector3df emDirection, u32 minParticlesPerSec, u32 maxParticlesPerSec, 
video::SColor minStrtColor, video::SColor maxStrtColor, u32 lifeTimeMin, u32 lifeTimeMax)
{


	// add particle system
	IParticleSystemSceneNode* ps = smgr->addParticleSystemSceneNode(false, 0);

	ps->setParticleSize(particleSize);

	// create and set emitter
	
	IParticleEmitter* em = ps->createBoxEmitter(
		boxEmmitterSize,emDirection, minParticlesPerSec,maxParticlesPerSec,
		minStrtColor, maxStrtColor, lifeTimeMin,lifeTimeMax);
	ps->setEmitter(em);
	em->drop();


	// create and set affector
	scene::IParticleAffector* paf = ps->createFadeOutParticleAffector();
	ps->addAffector(paf);
	paf->drop();

	// adjust some material settings
	ps->setMaterialFlag(video::EMF_LIGHTING, false);
	ps->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
	ps->setMaterialTexture(0, driver->getTexture(particleTextFilePath));
	ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);

	if (hasLight)
	{// add light 2 (gray)
		scene::ILightSceneNode* light2 =
		smgr->addLightSceneNode(ps, core::vector3df(0,0,0), lightColor, lightRange);
		
	}

	// add fly circle animator to light 2
	//anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),200.0f, 0.001f, core::vector3df ( 0.2f, 0.9f, 0.f ));
	//light2->addAnimator(anim);
	//anim->drop();

	if (hasBillBoard)
	{
	// attach billboard to light
	IBillboardSceneNode* bill = smgr->addBillboardSceneNode(ps, core::dimension2d<f32>(120, 120));
	bill->setMaterialFlag(video::EMF_LIGHTING, false);
	bill->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
	bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	bill->setMaterialTexture(0, driver->getTexture(billBoardFilePathImg));
	}
	

	return ps;
}